home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
program
/
rcs5ap1s.lzh
/
RCSFNMS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-30
|
34KB
|
1,227 lines
/*
* RCS file name handling
*/
/****************************************************************************
* creation and deletion of /tmp temporaries
* pairing of RCS file names and working file names.
* Testprogram: define PAIRTEST
****************************************************************************
*/
/* Copyright (C) 1982, 1988, 1989 Walter Tichy
Copyright 1990 by Paul Eggert
Distributed under license by the Free Software Foundation, Inc.
This file is part of RCS.
RCS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
RCS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RCS; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
Report problems and direct all questions to:
rcs-bugs@cs.purdue.edu
*/
/* $Log: rcsfnms.c,v $
* Revision 5.7 1991/01/30 14:13:06 apratt
* Fixed a bug: bindex returns ptr to char PAST match if there's a match.
*
* Revision 5.7 1991/01/30 14:11:14 apratt
* Fixed a bug: bindex returns ptr to char PAST match if there's a match.
*
* Revision 5.6 91/01/29 17:45:54 apratt
* Added AKP_BUGFIXES around my bug fixes, changed headstr
*
* Revision 5.5 91/01/16 15:45:00 apratt
* This version works passably on the ST.
*
* Revision 5.4 90/11/01 05:03:43 eggert
* checked in with -k by apratt at 91.01.10.13.15.14.
*
* Revision 5.4 1990/11/01 05:03:43 eggert
* Permit arbitrary data in comment leaders.
*
* Revision 5.3 1990/09/14 22:56:16 hammer
* added more filename extensions and their comment leaders
*
* Revision 5.2 1990/09/04 08:02:23 eggert
* Fix typo when !RCSSEP.
*
* Revision 5.1 1990/08/29 07:13:59 eggert
* Work around buggy compilers with defective argument promotion.
*
* Revision 5.0 1990/08/22 08:12:50 eggert
* Ignore signals when manipulating the semaphore file.
* Modernize list of file name extensions.
* Permit paths of arbitrary length. Beware file names beginning with "-".
* Remove compile-time limits; use malloc instead.
* Permit dates past 1999/12/31. Make lock and temp files faster and safer.
* Ansify and Posixate.
* Don't use access(). Fix test for non-regular files. Tune.
*
* Revision 4.8 89/05/01 15:09:41 narten
* changed getwd to not stat empty directories.
*
* Revision 4.7 88/08/09 19:12:53 eggert
* Fix troff macro comment leader bug; add Prolog; allow cc -R; remove lint.
*
* Revision 4.6 87/12/18 11:40:23 narten
* additional file types added from 4.3 BSD version, and SPARC assembler
* comment character added. Also, more lint cleanups. (Guy Harris)
*
* Revision 4.5 87/10/18 10:34:16 narten
* Updating version numbers. Changes relative to 1.1 actually relative
* to verion 4.3
*
* Revision 1.3 87/03/27 14:22:21 jenkins
* Port to suns
*
* Revision 1.2 85/06/26 07:34:28 svb
* Comment leader '% ' for '*.tex' files added.
*
* Revision 4.3 83/12/15 12:26:48 wft
* Added check for KDELIM in file names to pairfilenames().
*
* Revision 4.2 83/12/02 22:47:45 wft
* Added csh, red, and sl file name suffixes.
*
* Revision 4.1 83/05/11 16:23:39 wft
* Added initialization of Dbranch to InitAdmin(). Canged pairfilenames():
* 1. added copying of path from workfile to RCS file, if RCS file is omitted;
* 2. added getting the file status of RCS and working files;
* 3. added ignoring of directories.
*
* Revision 3.7 83/05/11 15:01:58 wft
* Added comtable[] which pairs file name suffixes with comment leaders;
* updated InitAdmin() accordingly.
*
* Revision 3.6 83/04/05 14:47:36 wft
* fixed Suffix in InitAdmin().
*
* Revision 3.5 83/01/17 18:01:04 wft
* Added getwd() and rename(); these can be removed by defining
* V4_2BSD, since they are not needed in 4.2 bsd.
* Changed sys/param.h to sys/types.h.
*
* Revision 3.4 82/12/08 21:55:20 wft
* removed unused variable.
*
* Revision 3.3 82/11/28 20:31:37 wft
* Changed mktempfile() to store the generated file names.
* Changed getfullRCSname() to store the file and pathname, and to
* delete leading "../" and "./".
*
* Revision 3.2 82/11/12 14:29:40 wft
* changed pairfilenames() to handle file.sfx,v; also deleted checkpathnosfx(),
* checksuffix(), checkfullpath(). Semaphore name generation updated.
* mktempfile() now checks for nil path; freefilename initialized properly.
* Added Suffix .h to InitAdmin. Added testprogram PAIRTEST.
* Moved rmsema, trysema, trydiraccess, getfullRCSname from rcsutil.c to here.
*
* Revision 3.1 82/10/18 14:51:28 wft
* InitAdmin() now initializes StrictLocks=STRICT_LOCKING (def. in rcsbase.h).
* renamed checkpath() to checkfullpath().
*/
#include "rcsbase.h"
libId(fnmsId, "$Id: rcsfnms.c,v 5.7 1991/01/30 14:13:06 apratt Exp $")
const char *RCSfilename;
char *workfilename;
struct stat RCSstat, workstat; /* file status for RCS file and working file */
int haveworkstat;
#if !USE_AKP_PAIRS
static const char rcsdir[] = RCSDIR;
#endif
#define TEMPNAMES 4 /* must be at least DIRTEMPNAMES (see rcsedit.c) */
static char tfnames[TEMPNAMES][L_tmpnam]; /* unlink these when done */
static volatile int tfmade[TEMPNAMES]; /* if these flags are set */
struct compair {
const char *suffix, *comlead;
};
static const struct compair comtable[] = {
/* comtable pairs each filename suffix with a comment leader. The comment */
/* leader is placed before each line generated by the $Log keyword. This */
/* table is used to guess the proper comment leader from the working file's */
/* suffix during initial ci (see InitAdmin()). Comment leaders are needed */
/* for languages without multiline comments; for others they are optional. */
"a", "-- ", /* Ada */
"c", " * ", /* C */
"C", "// ", /* C++ in all its infinite guises */
"CC", "// ",
"c++", "// ",
"cc", "// ",
"cxx", "// ",
"cl", ";;; ", /* Common Lisp */
"cmf", "C ", /* CM FORTRAN */
"cs", " * ", /* C* */
"el", "; ", /* Emacs Lisp */
"f", "c ", /* Fortran */
"for", "c ",
"h", " * ", /* C-header */
"l", " * ", /* lex NOTE: conflict between lex and franzlisp */
"lisp",";;; ", /* Lucid Lisp */
"mac", "; ", /* macro vms or dec-20 or pdp-11 macro */
"me", ".\\\" ",/* me-macros t/nroff*/
"ml", "; ", /* mocklisp */
"mm", ".\\\" ",/* mm-macros t/nroff*/
"ms", ".\\\" ",/* ms-macros t/nroff*/
"p", " * ", /* Pascal */
"pl", "% ", /* Prolog */
"tex", "% ", /* TeX */
"y", " * ", /* yacc */
nil, "# " /* default for unknown suffix; must always be last */
};
void
ffclose(fptr)
FILE * fptr;
/* Function: checks ferror(fptr) and aborts the program if there were
* errors; otherwise closes fptr.
*/
{ if (ferror(fptr) || fclose(fptr)==EOF)
IOerror();
}
char *
maketemp(n)
int n;
/* Create a unique filename using n and the process id and store it
* into the nth slot in tfnames.
* Because of storage in tfnames, tempunlink() can unlink the file later.
* Returns a pointer to the filename created.
*/
{
char *p = tfnames[n];
if (!tfmade[n]) {
#if has_tmpnam
if (!tmpnam(p))
#else
VOID sprintf(p, "%sRCS%cXXXXXX", tmp(), 'A'+n);
if (!mktemp(p))
#endif
faterror("can't make temporary file name");
}
tfmade[n] = true;
return p;
}
void
tempunlink()
/* Clean up maketemp() files. May be invoked by signal handler.
*/
{
re